package com.ruoyi.goods.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.GoodsCategory;
import com.ruoyi.system.service.GoodsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods/category")
public class GoodsCategoryController {

    @Autowired
    private GoodsCategoryService goodsCategoryService;

    /**
     * 分类列表
     */
    @GetMapping("/list")
    public AjaxResult categoryList() {
        List<GoodsCategory> goodsCategories = goodsCategoryService.queryAllByLimit();
        return AjaxResult.success(goodsCategories);
    }

    /**
     * 添加分类
     *
     * @param goodsCategory 分类数据
     */
    @PostMapping("/save")
    public AjaxResult saveCategory(@RequestBody GoodsCategory goodsCategory) {
        goodsCategoryService.insert(goodsCategory);
        return AjaxResult.success();
    }

    /**
     * 根据Id删除Id
     *
     * @param id 分类Id
     */
    @DeleteMapping("/del/{id}")
    public AjaxResult delCategory(@PathVariable("id") int id) {
        goodsCategoryService.deleteById(id);
        return AjaxResult.success("删除成功");
    }

    @GetMapping("/categorys")
    public AjaxResult categorys() {
        List<GoodsCategory> goodsCategories = goodsCategoryService.queryAllByLimit();
        return AjaxResult.success(goodsCategories);
    }
}
